<?php


namespace support\bootstrap;

use Illuminate\Events\Dispatcher;
use Webman\Bootstrap;
use Illuminate\Container\Container;

class Event implements Bootstrap
{
    /**
     * @var Dispatcher
     */
    protected static $instance = null;

    public static function start($worker)
    {
        $container = new Container;
        self::$instance = new Dispatcher($container);
        $eventsList = config('events');
        foreach ($eventsList as $event => $listener) {
            if (is_string($listener)) {
                $listener[] = implode(',', $listener);
            }
           foreach ($listener as $l) {
               self::$instance->listen($event, $l);
           }
        }
    }

    /**
     * instance
     * @return
     */
    public static function instance()
    {
        return static::$instance;
    }

}
